<?php

namespace app\api\controller\offline_store;

use app\api\BaseController;
use app\api\service\ShopsService;
use think\exception\ValidateException;
use think\facade\Request;

class StorelController extends BaseController
{

    /**
     * 商品列表
     */
    public function goodsList()
    {
        $param = $this->request->param();
        if (empty($param['store_id'])) {
            return json(['code' => 0, 'msg' => '参数有误']);
        }
        if (empty($param['shop_id'])) {
            return json(['code' => 0, 'msg' => '未找到指定店铺!']);
        }
        $list = ShopsService::goodsList($param['shop_id'], $param['store_id']);
        return json(['code' => 1, 'data' => $list, 'msg' => '查询成功']);
    }

     /**
     * 其他人的店铺信息
     */
    public function shopInfo()
    {
        $param = $this->request->param();
        if (empty($param['shop_id'])) {
            return json(['code' => 0, 'msg' => '未找到指定店铺!']);
        }
        if (empty($param['store_id'])) {
            return json(['code' => 0, 'msg' => '非法参数!']);
        }
        $rst = ShopsService::findShopInfo($param['shop_id'], $param['store_id']);
        return json(['code' => 1, 'data' => $rst, 'msg' => '查询成功']);
    }

    /**
     * 商圈列表
     */
    public  function offlineShops()
    {
        $param = $this->request->param();
        if (empty($param['store_id'])) {
            return json(['code' => 0, 'msg' => '非法参数!']);
        }
        // if (empty($param['lat']) || empty($param['lng'])) {
        //     return json(['code' => 0, 'msg' => '位置获取失败!']);
        // }
        $list = ShopsService::offlineShops($param);

        return json(['code' => 1, 'data' => $list, 'msg' => '请求成功!']);
    }

    /**
     * 商圈分类
     */
    public function storeCategory()
    {
        $param = $this->request->param();
        if (empty($param['store_id'])) {
            return json(['code' => 0, 'msg' => '非法参数!']);
        }
        $list = ShopsService::category($param);

        return json(['code' => 1, 'data' => $list, 'msg' => '请求成功!']);
    }

    /**
     * 商圈标签列表
     */
    public function label()
    {
        $param = $this->request->param();
        if (empty($param['store_id'])) {
            return json(['code' => 0, 'msg' => '非法参数!']);
        }
        $list = ShopsService::label($param);

        return json(['code' => 1, 'data' => $list, 'msg' => '请求成功!']);
    }
}
